package sg.edu.nus.iss.pacman.form;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import sg.edu.nus.iss.pacman.midlet.PacManMIDlet;

/**
 * This is Main Menu Screen
 * 
 * @author Daniel
 *
 */
public class MainMenuList extends List implements CommandListener {
	
	private static final String TITLE = "Main Menu";
	private PacManMIDlet mainApp;
	
	private Command cmdExit;
	private Command cmdSelect;
	
	private String[] choices = new String[]{"Play Game", 
											"View Score",
											"Download Maze",
											"Send Challenge"};
	
	/**
	 * Constructor for this screen
	 * @param mainApp PacManMIDlet
	 */
	public MainMenuList(PacManMIDlet mainApp) {
		super(TITLE, List.IMPLICIT, new String[]{}, null);
		this.mainApp = mainApp;
		init();
	}
	
	/**
	 * Intializes the screen
	 */
	private void init() {
		cmdExit = new Command(PacManMIDlet.LABEL_CMD_EXIT, Command.EXIT, 1);
		cmdSelect = new Command(PacManMIDlet.LABEL_CMD_SELECT, Command.OK, 1);
		
		insert(0, choices[0], null);
		insert(1, choices[1], null);
		insert(2, choices[2], null);
		insert(3, choices[3], null);
		
		addCommand(cmdExit);
		addCommand(cmdSelect);
		setCommandListener(this);
	}

	/**
	 * This is a method which handles command actions
	 */
	public void commandAction(Command cmd, Displayable disp) {
		if (cmd == cmdExit) {
			mainApp.quit();
		} else if (cmd == cmdSelect) {
			
			if (getSelectedIndex() == 0) {
				mainApp.displaySelectMazeList();
			} else if (getSelectedIndex() == 1) {
				mainApp.displayViewMapHighScore();
			} else if (getSelectedIndex() == 2) {
				mainApp.displayDownloadedMazeList();
			} else if (getSelectedIndex() == 3) {
				mainApp.displaySendChallengeChoiceList();
			}
		}

	}

}
